'''
 * CaRComp Execution Environment
 * 
 * Copyright (C) 2011 Taylor L. Riche
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
'''

from carcomp.framework import application, connector
from carcomp.framework.file_io import file_reader, file_writer
from carcomp.directory import localhost
from carcomp.apps.gamma import bloomhj

class GammaApp(application.Application):
    
    def __init__(self):
        application.Application.__init__(self)
        frA = file_reader.FileReaderComponent('{}ft/gamma/TEST_INPUT_A.txt'.format(localhost.local_directory.package_root), 'ARead')
        frB = file_reader.FileReaderComponent('{}ft/gamma/TEST_INPUT_B.txt'.format(localhost.local_directory.package_root), 'BRead')
        fw = file_writer.FileWriterComponent('{}ft/gamma/TEST_OUTPUT.txt'.format(localhost.local_directory.package_root))
        hj = bloomhj.ParBloomHashJoinAbs('HashJoin_alg0')
        self.add_components([frA, frB, fw, hj])
        hj_fw = connector.Connector(self._components['HashJoin_alg0'].get_endpoint('AB'),
                                    fw.get_input_endpoint())
        frA_hj = connector.Connector(frA.get_output_endpoint(),
                                    self._components['HashJoin_alg0'].get_endpoint('A'))
        frB_hj = connector.Connector(frB.get_output_endpoint(),
                                    self._components['HashJoin_alg0'].get_endpoint('B'))
        self.add_connections([frA_hj, frB_hj, hj_fw])
        self.resolve_abstractions()
        self.instrument('{}ft/gamma/data/'.format(localhost.local_directory.package_root))

if __name__ == '__main__':
    app = GammaApp()
    app.execute(True, 1)